﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Web;
using DevCore.Service.System;
using DevCore.Utility;
using DevCore.Web;

namespace DevFrameWork.Web.AppService.SysBo.SysFunc
{
    /// <summary>
    /// 系统基础功能处理
    /// </summary>
    public class BaseFunctionHandler : IHttpHandler
    {
        private String _funcCode = String.Empty;

        /// <summary>
        /// 处理数据.
        /// </summary>
        /// <param name="context"></param>
        public void ProcessRequest(HttpContext context)
        {
            //context.Response.Buffer = true;
            //context.Response.ExpiresAbsolute = System.DateTime.Now.AddSeconds(-1);
            //context.Response.Expires = 0;
            //context.Response.CacheControl = "no-cache ";
            String retContent = "";
            _funcCode = RequestHelper.GetQueryString("FuncCode");
            retContent = GetDataTableByFunc();
            context.Response.ContentType = "text/plain";
            context.Response.Write(retContent);
        }

        /// <summary>
        /// 得到当前的数据，并将当前的数据转换为符合EasyGrid格式的信息.
        /// </summary>
        /// <returns></returns>
        private String GetDataTableByFunc()
        {
            String retValue = "";
            int allCount = 0;
            DataTable dtInfo = FunctionService.GetFuncDataTable(0, _funcCode, 1, 10, "", "", out allCount);
            retValue = JsonHelper.DtToEasyUIDataGridJson(dtInfo, allCount);
            return retValue;
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}
